import 'package:app_admin/extension/custom_ext.dart';
import 'package:app_admin/models/order_set_info.dart';
import 'package:app_admin/pages/orderSet/orderSet_logic.dart';
import 'package:app_admin/res/strings.dart';
import 'package:app_admin/res/styles.dart';
import 'package:app_admin/routes/app_navigator.dart';
import 'package:app_admin/widgets/title_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class OrderSetPage extends StatelessWidget {
  final logic = Get.find<OrderSetLogic>();

  OrderSetPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TitleBar.backAndAdd(
        title: StrRes.orderSet,
        backgroundColor: Styles.c_0089FF,
        onAddFun: logic.addSet,
      ),
      backgroundColor: Styles.c_F8F9FA,
      body: Obx(() => ListView.builder(
            padding: EdgeInsets.only(top: 10.h),
            itemCount: logic.datas.length,
            itemBuilder: (_, index) => _buildItemView(logic.datas[index]),
          )),
    );
  }

  Widget _buildItemView(OrderSetInfo info) => Container(
        margin: EdgeInsets.all(10.w), //内边距
        padding: EdgeInsets.all(10.w),
        decoration: BoxDecoration(
          color: Styles.c_F8F9FA,
          border: Border.all(color: Styles.c_E8EAEF, width: 4.w),
          borderRadius: BorderRadius.circular(10.r),
        ),
        child: Column(
          children: [
            Row(mainAxisAlignment: MainAxisAlignment.start, children: [
              StrRes.orderCode.toText..style = Styles.ts_0C1C33_12sp,
              info.order!.toText..style = Styles.ts_0C1C33_12sp,
              const Spacer(),
              StrRes.orderTime.toText..style = Styles.ts_0C1C33_12sp,
              info.orderTime!.toText..style = Styles.ts_0C1C33_12sp,
            ]),
            10.verticalSpace,
            Row(mainAxisAlignment: MainAxisAlignment.start, children: [
              Container(
                width: 100.w,
                alignment: Alignment.centerRight,
                child: StrRes.orderPlayerName.toText
                  ..style = Styles.ts_0C1C33_12sp,
              ),
              30.horizontalSpace,
              info.orderPlayerName!.toText..style = Styles.ts_0C1C33_12sp,
              const Spacer(),
            ]),
            10.verticalSpace,
            Row(mainAxisAlignment: MainAxisAlignment.start, children: [
              Container(
                width: 100.w,
                alignment: Alignment.centerRight,
                child: StrRes.orderGoods.toText..style = Styles.ts_0C1C33_12sp,
              ),
              30.horizontalSpace,
              info.goods!.toText..style = Styles.ts_0C1C33_12sp,
              const Spacer(),
            ]),
            10.verticalSpace,
            Row(mainAxisAlignment: MainAxisAlignment.start, children: [
              Container(
                width: 100.w,
                alignment: Alignment.centerRight,
                child: StrRes.orderLevel.toText..style = Styles.ts_0C1C33_12sp,
              ),
              30.horizontalSpace,
              info.level!.toText..style = Styles.ts_0C1C33_12sp,
              const Spacer(),
            ]),
            10.verticalSpace,
            Row(mainAxisAlignment: MainAxisAlignment.start, children: [
              Container(
                width: 100.w,
                alignment: Alignment.centerRight,
                child: StrRes.orderNum.toText..style = Styles.ts_0C1C33_12sp,
              ),
              30.horizontalSpace,
              info.GetNumStr().toText..style = Styles.ts_0C1C33_12sp,
              const Spacer(),
            ]),
            10.verticalSpace,
            Row(mainAxisAlignment: MainAxisAlignment.start, children: [
              const Spacer(),
              GestureDetector(
                  behavior: HitTestBehavior.translucent,
                  onTap: () => logic.viewData(info),
                  child: "详情".toText..style = Styles.ts_0C1C33_12sp),
            ]),
          ],
        ),
      );
}
